var webPath = "";
var msgRows = "5";
$(document).ready(function(){
	webPath = $("#webPath").val();
	var msg = $("#message").val();
	if(msg != ""){
		alert(msg);
	}
});

function changePortlet(obj){
	var portletTitle = $(obj).parent().next().next().children("input");
	var portletType = portletTitle.parent().next().next().next().next().children("select");
	var portletPath = portletTitle.parent().next().next().next().next().next().next().children("input");
	$(obj).next().next().next().val($(obj).val());
	if($(obj).val() == ""){
		portletTitle.val("");
		portletPath.val("");
	}else if($(obj).val() == "-1"){
		portletType.attr("disabled",true);
		portletTitle.val("友情链接");
		portletPath.val("/portlet/relatedLink/00");
	}else if($(obj).val() == "-2"){
		portletType.attr("disabled",true);
		portletTitle.val("");
		portletPath.val("/portlet/lcoIntro/010");
	}else if($(obj).val() == "-3"){
		portletType.attr("disabled",true);
		portletTitle.val("");
		portletPath.val("/portlet/leaderIntro/00");
	}else{
		portletType.attr("disabled",false);
		if(portletType.val() != "custom"){
			portletTitle.val($(obj).find("option:selected").text());
			var method = portletType.find("option:selected").val();
			method = "/portlet/" + method + "/" + $(obj).val();
			portletPath.val(method);
		}
	}
}

function changePortletType(obj){
	var portlet = $(obj).parent().prev().prev().prev().prev().prev().prev().children("select");
	var portletPath = $(obj).parent().next().next().children("input");
	if(portlet.val() != ""){
		var method = "/portlet/" + $(obj).val() + "/" + portlet.val();
		portletPath.val(method);
	}
	if($(obj).val() == "custom"){
		portletPath.val("");
	}
}

function addPortlet(flag){
	var newP = $("#tr-condition-"+flag).clone().appendTo(".table_"+flag);
	$(newP).find("input").val("");
	$(newP).children().eq(1).children().eq(2).val(flag);
}

function delPortlet(obj){
	var partentTB = $(obj).parent().parent().parent();
	if(partentTB.children().size() <= 2){
		alert("至少保留一个模块");
	}else{
		$(obj).parent().parent().remove();
	}
}

function submitPortlet(){
	var portlet = $(".portlet");
	var portletLength = portlet.length;
	for(var i=0;i<portletLength;i++){
		var portletPosition = $(portlet[i]).next();
		var portletMsgType = $(portlet[i]).next().next();
		var portletTitle = $(portlet[i]).parent().next().next().children("input");
		var portletPath = portletTitle.parent().next().next().next().next().next().next().children("input");
		var displayTitle = portletTitle.parent().next().next().children("input");
		var portletType = portletTitle.parent().next().next().next().next().children("select");
		if(displayTitle.attr("checked")){
			displayTitle = "1";
		}else{
			displayTitle = "0";
		}

		if(string.trim(portletPath.val()) == ""){
			alert("请输入模块路径！");
			return false;
		}
		var tmp = (i+1) + "~" 
			+ portletPosition.val() + "~" 
			+ portletTitle.val() + "~" 
			+ portletPath.val() + "~" 
			+ portletMsgType.val() + "~"
			+ displayTitle + "~"
			+ portletType.val();
		$(portlet[i]).val(tmp)
	}
	
	document.form1.action = webPath + "/admin/portlet!change.action";
	document.form1.submit();
}

function goBack(){
	document.form1.action = webPath + "/admin/theme!list.action";
	document.form1.submit();
}